Corresponding software must be designed and implemented simultaneously when a chip is designed. In this case, because an actual chip does not exist, there must be a means of simulating an action of an actual chip, so as to provide an environment for software designing and debugging. A simulator is software with such a function.
A basic principle of a simulator is first reading a segment of a binary instruction code stream, translating it into an assembly instruction by using a decoder, then, simulating an action of the instruction according to a definition of the instruction, and finally implementing a function of this segment of code on a target chip.
In an existing technical solution, one simulator generation method is manually writing a decoding algorithm by a simulator developer. A main procedure of such a method is as follows:
1. A coding format of an instruction set is manually analyzed, and a bit field related to operation code is determined.
2. A sequence of applying each bit field to a decoding algorithm is manually determined.
3. A value corresponding to each instruction in each bit field is manually determined.
4. Code is manually written, values that may exist in bit fields are differentiated according to the foregoing sequence of the bit fields, and if the operation code can be determined, the operation code is returned; otherwise, comparison is performed in a next bit field.
In an existing technical solution, another simulator generation method is manually analyzing a coding format of an instruction set by a simulator developer, and generating final code by using a tool, and such a method is called a semi-manual method. A main procedure of such a method is as follows:
1. A coding format of an instruction set is manually analyzed, and a bit field of a binary instruction is manually divided.
2. A sequence of applying each bit field to a decoding algorithm is manually determined.
3. A value corresponding to each instruction in each bit field is manually determined.
4. Code is generated by using a tool.
In a process of implementing the foregoing simulator generation method, the inventor finds that the prior art at least has the following problems:
First, the workload of manual analysis and code writing is very heavy, an error may easily occur, and the cost of a post test is high; second, the work period of the manual analysis and code writing is long; and third, generally, simulator development and chip designing are performed synchronously, that is, the simulator needs to be put into development and application before an instruction set and its coding format are finally determined, which means that a decoding algorithm of the simulator may be changed at any time, and it is required that the change can be rapidly completed and put into use. The manual method or the semi-manual method cannot accommodate the requirement.
Based on such problems, the simulator cannot be rapidly ported and does not have high efficiency.